# Maintainer: Alexander Epaneshnikov <alex19ep@archlinux.org>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Pierre Neidhardt <ambrevar@gmail.com>
# Contributor: Renato Garcia <fgarcia.renato@gmail.com>

pkgname=trash-cli
pkgver=0.23.2.13.2
pkgrel=2
pkgdesc="Command line trashcan (recycle bin) interface"
arch=('any')
url="https://github.com/andreafrancia/trash-cli"
license=('GPL')
depends=('python-psutil' 'python-six')
makedepends=('python-setuptools' 'python-shtab')
checkdepends=('python-pytest' 'python-flexmock' 'python-parameterized')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
sha256sums=('98123bedccd88a970d78f696b4211669593d21e1e2e64f86f9546bf680a29bf2')

prepare() {
    cd "${srcdir}"/${pkgname}-${pkgver}

    # don't depend on thirdparty copies of the stdlib
    find tests -type f -name "*.py" -exec \
        sed -i 's/^import mock$/from unittest import mock/;s/from mock /from unittest.mock /;s/from mock.mock /from unittest.mock /' {} +
}

build() {
    cd "${srcdir}"/${pkgname}-${pkgver}

    python setup.py build
    for cmd in trash-empty trash-list trash-restore trash-put trash; do
      ./$cmd --print-completion bash > ./$cmd-completion
      ./$cmd --print-completion zsh > ./_$cmd-completion
    done
}

check() {
    cd "${srcdir}"/${pkgname}-${pkgver}

    python -m pytest
}

package(){
    cd "${srcdir}"/${pkgname}-${pkgver}

    python setup.py install --root="${pkgdir}" --optimize=1 --skip-build
    for cmd in trash-empty trash-list trash-restore trash-put trash; do
      install -vDm 644 ./$cmd-completion "$pkgdir/usr/share/bash-completion/completions/$cmd"
      install -vDm 644 ./_$cmd-completion "$pkgdir/usr/share/zsh/site-functions/_$cmd"
    done
}
